package com.yanchangapp.ui.presenter;

import com.yanchangapp.base.HeadApiRetrofit;
import com.yanchangapp.commom.AppConstant;
import com.yanchangapp.model.request.FinishPlanRequest;
import com.yanchangapp.ui.view.NotFinishAtView;
import com.zxl.baselib.bean.response.BaseResponse;
import com.zxl.baselib.ui.base.BaseActivity;
import com.zxl.baselib.ui.base.BaseObserver;
import com.zxl.baselib.ui.base.BasePresenter;
import com.zxl.baselib.ui.base.ExceptionHandle;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by apple on 2019-10-14.
 * description: 未完成P层
 */
public class NotFinishAtPresenter extends BasePresenter<NotFinishAtView> {
    public NotFinishAtPresenter(BaseActivity context) {
        super(context);
    }

    public void cannotFinishPlan(long id,String conclusion){
        getView().showLoadingDialog();
        HeadApiRetrofit.getInstance().putCannotFinishPlan(id,new FinishPlanRequest(conclusion))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<BaseResponse>() {
                    @Override
                    public void onNext(BaseResponse baseResponse) {
                        if (getView() != null){
                            getView().hideLoadingDialog();
                            if (baseResponse.getCode() == AppConstant.REQUEST_SUCCESS){
                                getView().cannotFinishSuccess();
                            }else {
                                getView().cannotFinishFailure(baseResponse.getMsg());
                            }
                        }
                    }

                    @Override
                    public void onError(ExceptionHandle.ResponseException exception) {
                        if (getView() != null){
                            getView().hideLoadingDialog();
                            getView().cannotFinishFailure("网络错误");
                        }
                    }
                });
    }
}
